#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

bool cmp(std::pair<std::string, int> a, std::pair<std::string, int> b)
{
    if ((a.second > b.second) || (a.second == b.second && a.first < b.first))
    {
        return true;
    }
    return false;
}

int main()
{
    std::string t;

    std::map<std::string, int> url_static;
    int first = true;
    while (std::getline(std::cin, t))
    {
        // std::cout << t << std::endl;

        if ((t.size() == 2 && t == "10") || (t.size() == 1 && t[0] <= '9' && t[0] >= '1'))
        {
            std::vector<std::pair<std::string, int>> url_count;
            for (auto it = url_static.begin(); it != url_static.end(); it++)
            {
                url_count.push_back({it->first, it->second});
            }

            std::sort(url_count.begin(), url_count.end(), cmp);

            int k = std::stoi(t);
            int v = url_count.size();

            if (!first)
            {
                std::cout << ",";
            }

            for (int i = 0; i < std::min(k, v) - 1; i++)
            {
                std::cout << url_count[i].first << " ";
            }

            std::cout << url_count[std::min(k, v) - 1].first;

            if (first)
            {
                first = false;
            }
        }
        else
        {
            url_static[t]++;
        }
    }

    return 0;
}